const Koa = require('koa');
const Router = require('koa-router');
const app = new Koa();
const router = new Router();

const Vue = require('vue');
const VueServerRenderer = require('vue-server-renderer')

const fs = require('fs');
const path =require('path')

const template = fs.readFileSync(path.resolve(__dirname,'./src/index.html'),'utf8')

const vm = new Vue({
    data(){
        return {
            name:'zf'
        }
    },
    template:'<div>hello {{name}}</div>'
})
const render =  VueServerRenderer.createBundleRenderer({},{
    template
})
// console.log(render)

router.get('/',async(ctx)=>{
    ctx.body=render.renderToStream(vm)
})

app.use(router.routes())
app.listen(3000,function () {
    console.log('serve start 3000')
})